package com.sparrow.rpc.socket.listenner;

import com.sparrow.rpc.domain.RpcNode;
import com.sparrow.rpc.socket.msg.req.RpcLoginRequest;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;

/**
 * 节点连接成功listener, 会立即发送登录中心服请求
 */
public class GameCenterNodeConnectListener implements ChannelFutureListener {

    private RpcNode self;

    public GameCenterNodeConnectListener(RpcNode self) {
        this.self = self;
    }

    @Override
    public void operationComplete(ChannelFuture f) throws Exception {
        Channel c = f.channel();
        RpcLoginRequest regReq = new RpcLoginRequest(self.getId(), self.getIp(), self.getPort());
        c.writeAndFlush(regReq);
    }
}
